//
//  MyVoiceView.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/1/16.
//

import SwiftUI

//我的音色
struct MyVoiceView: View {
    //用于父试图来管理数据
    @ObservedObject var viewModel : MyVoiceViewModel
    var choose = false
    let onChoose: (AiVoiceBean) -> Void

    var body: some View {
        ZStack{
            if !viewModel.status.isEmpty {
                HomeEmptyView(text1: viewModel.status)
            } else {
                ScrollView {
                    // 数据列表
                    ForEach(viewModel.items) { item in
                        SystemVoiceItemView(item: item,choose: choose) { aiVoiceBean in
                            onChoose(aiVoiceBean)
                        }
                    }
                    
                    LoadMoreFooter(refreshing: $viewModel.footerRefreshing, action: {
                        viewModel.getData(false)
                    }) {
                        LoadMoreView(noMore: viewModel.noMore, footerRefreshing: viewModel.footerRefreshing)
                    }
                    .noMore(viewModel.noMore)
                    .preload(offset: 10)
                }
                .enableRefresh()
                .onAppear {
                    if !viewModel.isInit {
                        viewModel.getData(true)
                        viewModel.isInit = true
                    }
                }
            }
        }
    }
}

#Preview {
    MyVoiceView(viewModel:MyVoiceViewModel()){_ in}
}
